<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>SSE Client</title>
</head>
<body>
  <h1>Connecting to /sse...</h1>
  <pre id="output"></pre>

  <script>
    const output = document.getElementById('output');

    // 连接到你的 SSE 服务
    const eventSource = new EventSource('http://localhost:8086/sse');

    // 监听消息
    eventSource.onmessage = function(event) {
      const message = event.data;
      output.textContent += message + '\n';
    };

    // 监听连接打开
    eventSource.onopen = function() {
      output.textContent += 'Connection opened\n';
    };

    // 监听错误
    eventSource.onerror = function(err) {
      output.textContent += 'Connection error:\n' + JSON.stringify(err, null, 2) + '\n';
    };
  </script>
</body>
</html>